﻿using Abp.AutoMapper;
using ImageProcessor.Imaging.Formats;
using System;
using System.ComponentModel.DataAnnotations;

namespace FutureApp.Web.Models.Media
{
    /// <summary>
    /// 图片视图模型
    /// </summary>
    public class DownloadPictureViewModel
    {
        /// <summary>
        /// 图片标识
        /// </summary>
        public Guid Id { get; set; }

        /// <summary>
        /// 格式
        /// </summary>
        public string Format { get; set; }

        /// <summary>
        /// 图片宽度
        /// </summary>
        [Range(0, int.MaxValue)]
        public int Width { get; set; }

        /// <summary>
        /// 图片高度
        /// </summary>
        [Range(0, int.MaxValue)]
        public int Height { get; set; }

        private ISupportedImageFormat imageFormat;
        /// <summary>
        /// 文件格式
        /// </summary>
        public ISupportedImageFormat ImageFormat
        {
            get
            {
                return this.imageFormat ?? (this.imageFormat = this.Format.MapTo<ISupportedImageFormat>());
            }
        }

        /// <summary>
        /// 图片是否需要处理
        /// </summary>
        public bool NeedProcess
        {
            get
            {
                return !(this.ImageFormat == null
                    && this.Width == 0
                    && this.Height == 0);
            }
        }

        /// <summary>
        /// 压缩文件名称
        /// </summary>
        public string ThumbsName
        {
            get
            {
                return $"{this.Id.ToString("N")}[{this.Width},{this.Height}]";
            }
        }
    }
}
